<template>
  <div class="ai-assistant-page">
    <el-card class="welcome-card">
      <template #header>
        <div class="card-header">
          <el-icon class="ai-icon"><MagicStick /></el-icon>
          <span class="title">AI低代码助手</span>
        </div>
      </template>

      <div class="welcome-content">
        <h2>👋 欢迎使用AI低代码助手</h2>
        <p>我可以帮助你快速创建各种页面、表单、流程和数据模型，只需用自然语言描述你的需求即可。</p>
        
        <el-row :gutter="20" style="margin-top: 30px">
          <el-col :span="6">
            <el-card class="feature-card" shadow="hover">
              <el-icon class="feature-icon"><Edit /></el-icon>
              <h3>表单生成</h3>
              <p>描述表单需求，自动生成完整的表单配置</p>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="feature-card" shadow="hover">
              <el-icon class="feature-icon"><Document /></el-icon>
              <h3>页面生成</h3>
              <p>根据需求自动创建页面布局和组件</p>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="feature-card" shadow="hover">
              <el-icon class="feature-icon"><Connection /></el-icon>
              <h3>流程设计</h3>
              <p>智能生成业务流程和审批流</p>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="feature-card" shadow="hover">
              <el-icon class="feature-icon"><DataAnalysis /></el-icon>
              <h3>数据模型</h3>
              <p>自动创建数据表结构和关系</p>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </el-card>

    <el-row :gutter="20" style="margin-top: 20px">
      <!-- 对话区域 -->
      <el-col :span="16">
        <el-card class="chat-card">
          <template #header>
            <div class="chat-header">
              <span>AI对话</span>
              <el-button-group>
                <el-button size="small" @click="handleNewChat">
                  <el-icon><Plus /></el-icon>
                  新对话
                </el-button>
                <el-button size="small" @click="handleClearChat">
                  <el-icon><Delete /></el-icon>
                  清空
                </el-button>
              </el-button-group>
            </div>
          </template>

          <div class="chat-container">
            <div class="messages" ref="messagesRef">
              <div v-for="(message, index) in messages" :key="index" class="message" :class="message.role">
                <div class="message-avatar">
                  <el-icon v-if="message.role === 'assistant'">
                    <MagicStick />
                  </el-icon>
                  <el-icon v-else-if="message.role === 'reasoning'">
                    <TrendCharts />
                  </el-icon>
                  <el-icon v-else>
                    <User />
                  </el-icon>
                </div>
                <div class="message-content">
                  <div 
                    class="message-text" 
                    :class="{ 'reasoning-text': message.role === 'reasoning' }"
                    v-html="formatMessage(message.content)"></div>
                  <div v-if="message.actions" class="message-actions">
                    <el-button
                      v-for="(action, idx) in message.actions"
                      :key="idx"
                      size="small"
                      type="primary"
                      @click="handleAction(action)"
                    >
                      {{ action.label }}
                    </el-button>
                  </div>
                </div>
              </div>

              <div v-if="loading" class="message assistant">
                <div class="message-avatar">
                  <el-icon class="rotating"><Loading /></el-icon>
                </div>
                <div class="message-content">
                  <div class="message-text">AI正在思考...</div>
                </div>
              </div>
            </div>

            <div class="input-area">
              <div class="input-wrapper">
                <el-button
                  circle
                  :type="isVoiceRecording ? 'danger' : 'default'"
                  :class="{ 'voice-active': isVoiceRecording }"
                  @click="toggleVoiceInput"
                  class="voice-input-btn"
                >
                  <el-icon :class="{ 'voice-pulse': isVoiceRecording }">
                    <Microphone />
                  </el-icon>
                </el-button>
                <el-input
                  v-model="userInput"
                  type="textarea"
                  :rows="3"
                  placeholder="请描述你的需求，或点击麦克风语音输入..."
                  @keydown.ctrl.enter="handleSendMessage"
                  class="ai-input-field"
                />
              </div>
              <div class="input-actions">
                <div class="quick-actions">
                  <el-tag
                    v-for="(template, index) in quickTemplates"
                    :key="index"
                    class="quick-tag"
                    @click="userInput = template.text"
                  >
                    {{ template.label }}
                  </el-tag>
                </div>
                <el-button type="primary" @click="handleSendMessage" :loading="loading">
                  <el-icon><Promotion /></el-icon>
                  发送 (Ctrl+Enter)
                </el-button>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>

      <!-- 历史记录和统计 -->
      <el-col :span="8">
        <el-card class="history-card">
          <template #header>
            <span>对话历史</span>
          </template>
          <div class="history-list">
            <div
              v-for="(chat, index) in chatHistory"
              :key="index"
              class="history-item"
              :class="{ active: currentChatIndex === index }"
              @click="loadChat(index)"
            >
              <div class="history-title">{{ chat.title }}</div>
              <div class="history-time">{{ chat.time }}</div>
            </div>
            <el-empty v-if="chatHistory.length === 0" description="暂无历史记录" />
          </div>
        </el-card>

        <el-card class="stats-card" style="margin-top: 20px">
          <template #header>
            <span>使用统计</span>
          </template>
          <div class="stats-list">
            <div class="stat-item">
              <el-icon><Edit /></el-icon>
              <div class="stat-info">
                <div class="stat-label">表单生成</div>
                <div class="stat-value">{{ stats.forms }}</div>
              </div>
            </div>
            <div class="stat-item">
              <el-icon><Document /></el-icon>
              <div class="stat-info">
                <div class="stat-label">页面生成</div>
                <div class="stat-value">{{ stats.pages }}</div>
              </div>
            </div>
            <div class="stat-item">
              <el-icon><Connection /></el-icon>
              <div class="stat-info">
                <div class="stat-label">流程生成</div>
                <div class="stat-value">{{ stats.flows }}</div>
              </div>
            </div>
            <div class="stat-item">
              <el-icon><DataAnalysis /></el-icon>
              <div class="stat-info">
                <div class="stat-label">数据模型</div>
                <div class="stat-value">{{ stats.models }}</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 语音识别动画面板 -->
    <transition name="voice-overlay">
      <div v-if="isVoiceRecording" class="voice-recognition-overlay">
        <div class="voice-recognition-panel">
          <!-- 动画区域 -->
          <div class="voice-animation-area">
            <!-- 中心圆环 -->
            <div class="voice-circle-container">
              <div class="voice-circle voice-circle-outer"></div>
              <div class="voice-circle voice-circle-middle"></div>
              <div class="voice-circle voice-circle-inner">
                <el-icon :size="48" class="voice-mic-icon">
                  <Microphone />
                </el-icon>
              </div>
            </div>

            <!-- 波形动画 -->
            <div class="voice-waves">
              <div class="voice-wave" v-for="i in 8" :key="i" :style="{ '--wave-index': i }"></div>
            </div>
          </div>

          <!-- 识别状态 -->
          <div class="voice-status">
            <div class="status-text">{{ voiceTranscript || '正在聆听，请说话...' }}</div>
            <div class="status-hint">
              <el-tag size="small" effect="plain">中文识别</el-tag>
              <el-tag size="small" effect="plain" type="success">实时转换</el-tag>
            </div>
          </div>

          <!-- 操作提示 -->
          <div class="voice-actions">
            <el-button type="danger" round @click="stopVoiceInput">
              <el-icon><Close /></el-icon>
              停止录音
            </el-button>
            <div class="voice-tip">
              <el-text size="small" type="info">
                说完后自动发送，或点击停止按钮
              </el-text>
            </div>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script setup>
import { ref, reactive, nextTick, onMounted, onUnmounted, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import {
  MagicStick, User, Loading, Plus, Delete, Edit, Document,
  Connection, DataAnalysis, Promotion, Microphone, Close, TrendCharts
} from '@element-plus/icons-vue'
import { createAgentAi } from '@/uses/agentAi'
import { marked } from 'marked'
import DOMPurify from 'dompurify'

const router = useRouter()

// 初始化AI助手
const { ws, sendMessage, agentModel, connected, messages, loading } = createAgentAi()

// 状态
const userInput = ref('')
const messagesRef = ref(null)

// 语音输入状态
const isVoiceRecording = ref(false)
const voiceRecognition = ref(null)
const isVoiceSupported = ref(false)
const voiceTranscript = ref('')

// 对话历史
const chatHistory = ref([])
const currentChatIndex = ref(-1)

// 统计数据
const stats = reactive({
  forms: 15,
  pages: 8,
  flows: 6,
  models: 12
})

// 快捷模板
const quickTemplates = [
  { label: '员工管理页面', text: '帮我创建一个员工管理的CRUD页面，包含员工列表、新增、编辑、删除功能' },
  { label: '请假申请流程', text: '创建一个请假申请流程，包含申请、主管审批、HR审批三个环节' },
  { label: '订单表单', text: '设计一个订单表单，包含客户信息、商品明细、金额计算等' },
  { label: '报表页面', text: '生成一个销售报表页面，带有图表展示和数据筛选功能' }
]

// 方法
const handleSendMessage = () => {
  if (!userInput.value.trim() || loading.value) {
    ElMessage.warning('请输入内容')
    return
  }

  const content = userInput.value.trim()
  userInput.value = ''

  // 发送消息到WebSocket
  if (connected.value) {
    sendMessage(content)
  } else {
    ElMessage.warning('AI助手未连接，请稍候再试')
  }
  
  // 保存到历史
  saveChatHistory(content)
}

// 初始化语音识别
const initVoiceRecognition = () => {
  const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition

  if (!SpeechRecognition) {
    console.warn('当前浏览器不支持语音识别')
    isVoiceSupported.value = false
    return
  }

  isVoiceSupported.value = true
  voiceRecognition.value = new SpeechRecognition()

  // 配置语音识别
  voiceRecognition.value.lang = 'zh-CN'
  voiceRecognition.value.continuous = false
  voiceRecognition.value.interimResults = true
  voiceRecognition.value.maxAlternatives = 1

  // 识别结果事件
  voiceRecognition.value.onresult = (event) => {
    const result = event.results[event.results.length - 1]
    const transcript = result[0].transcript

    if (result.isFinal) {
      // 最终结果
      voiceTranscript.value = transcript

      setTimeout(() => {
        isVoiceRecording.value = false
        userInput.value = transcript
        voiceTranscript.value = ''

        // 自动发送消息
        setTimeout(() => {
          handleSendMessage()
        }, 500)
      }, 800)
    } else {
      // 实时结果
      voiceTranscript.value = transcript
    }
  }

  // 识别开始
  voiceRecognition.value.onstart = () => {
    console.log('语音识别已开始')
    voiceTranscript.value = ''
  }

  // 识别结束
  voiceRecognition.value.onend = () => {
    console.log('语音识别已结束')
    if (isVoiceRecording.value && !voiceTranscript.value) {
      // 没有识别到内容
      isVoiceRecording.value = false
      ElMessage.warning('未识别到语音，请重试')
    }
  }

  // 识别错误
  voiceRecognition.value.onerror = (event) => {
    console.error('语音识别错误:', event.error)
    isVoiceRecording.value = false
    voiceTranscript.value = ''

    const errorMessages = {
      'no-speech': '未检测到语音，请重试',
      'audio-capture': '无法访问麦克风，请检查权限',
      'not-allowed': '麦克风权限被拒绝，请在浏览器设置中允许',
      'network': '网络错误，请检查网络连接',
      'aborted': '语音识别已取消'
    }

    const message = errorMessages[event.error] || '语音识别失败，请重试'

    if (event.error !== 'aborted') {
      ElMessage.error(message)
    }
  }
}

// 开始语音输入
const startVoiceInput = () => {
  if (!voiceRecognition.value) return
  try {
    isVoiceRecording.value = true
    voiceTranscript.value = ''
    voiceRecognition.value.start()
  } catch (error) {
    console.error('语音识别启动失败:', error)
    ElMessage.error('语音识别启动失败，请稍后重试')
    isVoiceRecording.value = false
  }
}

// 停止语音输入
const stopVoiceInput = () => {
  if (voiceRecognition.value && isVoiceRecording.value) {
    voiceRecognition.value.stop()
    isVoiceRecording.value = false
    voiceTranscript.value = ''
  }
}

// 切换语音输入
const toggleVoiceInput = () => {
  if (!isVoiceSupported.value) {
    ElMessage.warning('您的浏览器不支持语音识别，请使用Chrome或Edge浏览器')
    return
  }

  if (isVoiceRecording.value) {
    stopVoiceInput()
  } else {
    startVoiceInput()
  }
}

const formatMessage = (content) => {
  if (!content) return ''
  try {
    const html = marked.parse(content)
    return DOMPurify.sanitize(html)
  } catch (error) {
    console.error('Markdown渲染失败:', error)
    return content.replace(/\n/g, '<br>')
  }
}

const handleAction = (action) => {
  if (action.type === 'goto') {
    router.push(action.target)
  }
}

const scrollToBottom = () => {
  nextTick(() => {
    if (messagesRef.value) {
      messagesRef.value.scrollTop = messagesRef.value.scrollHeight
    }
  })
}

const handleNewChat = () => {
  if (messages.value.length > 1) {
    saveChatHistory('新对话')
  }
  
  messages.value = [
    {
      role: 'assistant',
      content: '你好！我是AI低代码助手。我可以帮你创建表单、页面、流程和数据模型。请告诉我你想要创建什么？'
    }
  ]
  currentChatIndex.value = -1
}

const handleClearChat = () => {
  messages.value = [
    {
      role: 'assistant',
      content: '你好！我是AI低代码助手。我可以帮你创建表单、页面、流程和数据模型。请告诉我你想要创建什么？'
    }
  ]
}

const saveChatHistory = (title) => {
  const chat = {
    title: title.substring(0, 20) + (title.length > 20 ? '...' : ''),
    time: new Date().toLocaleString(),
    messages: [...messages.value]
  }
  
  chatHistory.value.unshift(chat)
  if (chatHistory.value.length > 10) {
    chatHistory.value.pop()
  }
}

const loadChat = (index) => {
  currentChatIndex.value = index
  messages.value = [...chatHistory.value[index].messages]
  nextTick(() => {
    scrollToBottom()
  })
}

// 监听AI消息变化，自动滚动到底部
watch(() => messages.value, () => {
  scrollToBottom()
}, { deep: true })

// 监听AI加载状态
watch(() => loading.value, (isLoading) => {
  if (!isLoading) {
    scrollToBottom()
  }
})

onMounted(() => {
  initVoiceRecognition()
})

onUnmounted(() => {
  stopVoiceInput()
})
</script>

<style scoped>
.ai-assistant-page {
  padding: 20px;
  min-height: 100vh;
  background: #f5f5f5;
}

.welcome-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-icon {
  font-size: 24px;
  color: #409eff;
}

.title {
  font-size: 18px;
  font-weight: bold;
}

.welcome-content {
  text-align: center;
  padding: 20px;
}

.welcome-content h2 {
  margin-bottom: 15px;
  color: #303133;
}

.welcome-content p {
  color: #606266;
  font-size: 16px;
}

.feature-card {
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 20px rgba(64, 158, 255, 0.3);
}

.feature-icon {
  font-size: 48px;
  color: #409eff;
  margin-bottom: 15px;
}

.feature-card h3 {
  margin: 10px 0;
  color: #303133;
}

.feature-card p {
  color: #909399;
  font-size: 14px;
}

.chat-card {
  height: 700px;
}

.chat-card :deep(.el-card__body) {
  height: calc(100% - 57px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f9f9f9;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.message {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #409eff;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: #67c23a;
}

.message.reasoning .message-avatar {
  background: linear-gradient(135deg, #ff9a56 0%, #ff6a88 100%);
}

.message-content {
  flex: 1;
  max-width: 70%;
}

.message-text {
  padding: 12px 16px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-text {
  background: #409eff;
  color: white;
}

.message-text :deep(h1),
.message-text :deep(h2),
.message-text :deep(h3),
.message-text :deep(h4),
.message-text :deep(h5),
.message-text :deep(h6) {
  margin: 16px 0 8px 0;
  font-weight: 600;
  line-height: 1.25;
}

.message-text :deep(h1) { font-size: 1.75em; border-bottom: 1px solid #eaecef; padding-bottom: 0.3em; }
.message-text :deep(h2) { font-size: 1.5em; border-bottom: 1px solid #eaecef; padding-bottom: 0.3em; }
.message-text :deep(h3) { font-size: 1.25em; }
.message-text :deep(h4) { font-size: 1em; }
.message-text :deep(h5) { font-size: 0.875em; }
.message-text :deep(h6) { font-size: 0.85em; color: #6a737d; }

.message-text :deep(p) {
  margin: 8px 0;
}

.message-text :deep(a) {
  color: #0366d6;
  text-decoration: none;
}

.message-text :deep(a:hover) {
  text-decoration: underline;
}

.message-text :deep(code) {
  padding: 2px 6px;
  background: #f6f8fa;
  border-radius: 3px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9em;
  color: #e83e8c;
}

.message-text :deep(pre) {
  padding: 12px;
  background: #f6f8fa;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-text :deep(pre code) {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 0.9em;
}

.message-text :deep(blockquote) {
  padding: 0 1em;
  color: #6a737d;
  border-left: 4px solid #dfe2e5;
  margin: 8px 0;
}

.message-text :deep(ul),
.message-text :deep(ol) {
  margin: 8px 0;
  padding-left: 2em;
}

.message-text :deep(li) {
  margin: 4px 0;
}

.message-text :deep(table) {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
}

.message-text :deep(th),
.message-text :deep(td) {
  border: 1px solid #dfe2e5;
  padding: 6px 13px;
}

.message-text :deep(th) {
  background: #f6f8fa;
  font-weight: 600;
}

.message-text :deep(img) {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 8px 0;
}

.message-text :deep(hr) {
  border: none;
  border-top: 1px solid #eaecef;
  margin: 16px 0;
}

.reasoning-text {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-left: 3px solid #f59e0b;
  font-style: italic;
  color: #78350f;
}

.message-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
}

.input-area {
  flex-shrink: 0;
  border-top: 1px solid #e4e7ed;
  padding: 20px;
  background: white;
}

.input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.quick-tag {
  cursor: pointer;
}

.quick-tag:hover {
  opacity: 0.8;
}

.history-card, .stats-card {
  height: 340px;
}

.history-list {
  overflow-y: auto;
  max-height: 280px;
}

.history-item {
  padding: 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: all 0.3s;
  border: 1px solid transparent;
}

.history-item:hover {
  background: #f0f9ff;
  border-color: #409eff;
}

.history-item.active {
  background: #409eff;
  color: white;
}

.history-title {
  font-weight: bold;
  margin-bottom: 5px;
}

.history-time {
  font-size: 12px;
  opacity: 0.7;
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: #f9f9f9;
  border-radius: 8px;
}

.stat-item .el-icon {
  font-size: 32px;
  color: #409eff;
}

.stat-info {
  flex: 1;
}

.stat-label {
  color: #909399;
  font-size: 14px;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}

.rotating {
  animation: rotate 1s linear infinite;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.input-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.voice-input-btn {
  flex-shrink: 0;
  position: relative;
  margin-top: 0;
}

.voice-input-btn.voice-active {
  animation: voice-btn-pulse 1.5s infinite;
}

@keyframes voice-btn-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(245, 108, 108, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(245, 108, 108, 0);
  }
}

.voice-pulse {
  animation: icon-pulse 1s infinite;
}

@keyframes icon-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.ai-input-field {
  flex: 1;
}

/* 语音识别动画覆盖层 */
.voice-recognition-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.voice-recognition-panel {
  text-align: center;
  max-width: 600px;
  padding: 60px 40px;
}

/* 语音动画区域 */
.voice-animation-area {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 0 auto 40px;
}

.voice-circle-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.voice-circle {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-circle-outer {
  width: 280px;
  height: 280px;
  border: 3px solid rgba(64, 158, 255, 0.3);
  animation: circle-pulse-outer 3s ease-in-out infinite;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.voice-circle-middle {
  width: 200px;
  height: 200px;
  border: 3px solid rgba(64, 158, 255, 0.5);
  animation: circle-pulse-middle 2s ease-in-out infinite;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.voice-circle-inner {
  width: 120px;
  height: 120px;
  background: linear-gradient(135deg, #409eff 0%, #67c23a 100%);
  box-shadow: 0 10px 40px rgba(64, 158, 255, 0.5);
  animation: circle-pulse-inner 1.5s ease-in-out infinite;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.voice-mic-icon {
  color: white;
  animation: mic-bounce 1s ease-in-out infinite;
}

@keyframes circle-pulse-outer {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.3;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 0.6;
  }
}

@keyframes circle-pulse-middle {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.15);
    opacity: 0.8;
  }
}

@keyframes circle-pulse-inner {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 10px 40px rgba(64, 158, 255, 0.5);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.05);
    box-shadow: 0 15px 50px rgba(64, 158, 255, 0.8);
  }
}

@keyframes mic-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* 波形动画 */
.voice-waves {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.voice-wave {
  position: absolute;
  width: 4px;
  height: 60px;
  background: linear-gradient(180deg, #409eff 0%, #67c23a 100%);
  border-radius: 2px;
  top: 50%;
  left: 50%;
  animation: wave-animation 1.2s ease-in-out infinite;
  opacity: 0.8;
}

.voice-wave:nth-child(1) {
  transform: translate(-50%, -50%) rotate(0deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 1) * 0.1s);
}
.voice-wave:nth-child(2) {
  transform: translate(-50%, -50%) rotate(45deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 2) * 0.1s);
}
.voice-wave:nth-child(3) {
  transform: translate(-50%, -50%) rotate(90deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 3) * 0.1s);
}
.voice-wave:nth-child(4) {
  transform: translate(-50%, -50%) rotate(135deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 4) * 0.1s);
}
.voice-wave:nth-child(5) {
  transform: translate(-50%, -50%) rotate(180deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 5) * 0.1s);
}
.voice-wave:nth-child(6) {
  transform: translate(-50%, -50%) rotate(225deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 6) * 0.1s);
}
.voice-wave:nth-child(7) {
  transform: translate(-50%, -50%) rotate(270deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 7) * 0.1s);
}
.voice-wave:nth-child(8) {
  transform: translate(-50%, -50%) rotate(315deg) translateY(-140px);
  animation-delay: calc(var(--wave-index, 8) * 0.1s);
}

@keyframes wave-animation {
  0%, 100% {
    height: 40px;
    opacity: 0.4;
  }
  50% {
    height: 80px;
    opacity: 1;
  }
}

/* 语音状态显示 */
.voice-status {
  margin-bottom: 32px;
}

.status-text {
  font-size: 24px;
  font-weight: 500;
  color: white;
  margin-bottom: 16px;
  min-height: 32px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.status-hint {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* 语音操作按钮 */
.voice-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.voice-tip {
  color: rgba(255, 255, 255, 0.7);
}

/* 动画 */
.voice-overlay-enter-active,
.voice-overlay-leave-active {
  transition: all 0.4s ease;
}

.voice-overlay-enter-from {
  opacity: 0;
}

.voice-overlay-enter-from .voice-recognition-panel {
  transform: scale(0.8);
}

.voice-overlay-leave-to {
  opacity: 0;
}

.voice-overlay-leave-to .voice-recognition-panel {
  transform: scale(0.8);
}
</style>



